import 'package:flutter_ability/framework/vm/base_view_model.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

/// 封装ConsumerState父类
/// M 是ViewModel层用于处理数据 更新数据刷新UI
abstract class BaseState<M extends BaseViewModel,
    T extends ConsumerStatefulWidget> extends ConsumerState<T> {
  /// 标识
  String tag = T.toString();

  ///真实获取数据的仓库
  late M viewModel;

  @override
  void initState() {
    super.initState();
    viewModel = createViewModel();
    viewModel.initState();
  }

  @override
  void dispose() {
    super.dispose();
    viewModel.onDispose();
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }

  @override
  void didUpdateWidget(covariant T oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  M createViewModel();
}
